/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ttt.nor2.db;

import com.ttt.nor2.util.ExceptionUtil;
import java.sql.Connection;
import java.sql.DriverManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;


/**
 *
 * @author Administrator
 */
public class DBMysql {

    static private Logger logger = Logger.getLogger(DBMysql.class);

    static public Connection dbConn(String url, String user, String pwd, String dbName) {

        Connection conn = null;
        String connString;
        connString = "jdbc:mysql://" + url + "/" + dbName + "?user=" + user + "&password=" + pwd + "&characterEncoding=UTF-8";
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            DriverManager.setLoginTimeout(10);
            conn = DriverManager.getConnection(connString);

        } catch (Exception e) {
            logger.error("Can't connection db :" + connString + " Exception:" + ExceptionUtil.getStackTrace(e));
            System.exit(-1);
        }

        return conn;
    }


    public static Connection getConnection(String fileProp, String conn) {
        try {
            Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
            //logger.debug("file properties:[" + fileProp + "]");
            PropertyConfigurator.configure(fileProp);
            return DriverManager.getConnection("proxool.my" + conn);
            
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return null;
    }
}
